﻿
Imports System.Data
Imports System.Data.SqlClient


''' <summary>
''' 倉位設置
''' </summary>
''' <remarks>
''' <list>Create By:Huyang</list>
''' <list>Create Date:2007-04-27</list>
''' <list>Function : 倉位設置</list>
''' <list>Table:BSC_Storage</list>
''' </remarks>
Public Class Frm_BSCBin

    Implements IDServer.IDServer.IDServer

#Region "Variabled Define"

#Region "System Variabled Define"

    Public ActionHelp As IDServer.IDServer.ActionBtn = IDServer.IDServer.ActionBtn.ActionHelp

    Private WithEvents MainForm As Frm_MainForm

    Public Property SelectObject() As Frm_MainForm
        Get
            Return MainForm
        End Get
        Set(ByVal value As Frm_MainForm)
            MainForm = value
        End Set
    End Property

#End Region

#Region "User Variabled Define"

    ''' <summary>
    ''' 窗體是否已加載
    ''' </summary>
    ''' <remarks></remarks>
    Private fLoadBool As Boolean = False

    ''' <summary>
    ''' 倉庫/庫位數據集
    ''' </summary>
    ''' <remarks></remarks>
    Private StoreDset As New DataSet


    ''' <summary>
    ''' 是否是填充完成
    ''' </summary>
    ''' <remarks></remarks>
    Private fFillBool As Boolean = False


#End Region

#End Region

#Region "Method Define"

#Region "網格"

    ''' <summary>
    ''' 返回網格標頭
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function Re_CaptionHash() As Hashtable
        Dim Hash As New Hashtable
        Try
            With Hash
                .Add("fCode", "倉庫編號")
                .Add("fStoreName", "倉庫名稱")
                .Add("fStorageId", "庫位")
                .Add("fLength", "長度")
                .Add("fWidth", "寬度")
                .Add("fHeight", "高度")
                .Add("fPrice", "單價")
                .Add("fArea", "面積")
                .Add("fVolume", "體積")
                .Add("Remark", "備註")
                .Add("fVirtual", "壞貨庫位")
                .Add("fBuJian", "補件庫位")
            End With
        Catch ex As Exception
            MessageBox.Show("Re_CaptionHash:" & ex.Message & ex.StackTrace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
        Return Hash
    End Function

#End Region

#Region "查詢"

    ''' <summary>
    ''' 返回查詢條件
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function ReturnWhereExp() As String
        Dim Sql As String = ""
        Try
            If Me.fLoadBool = False Then
                Sql &= "  where 1<>1 "
            Else
                Sql &= " where 1=1 "
                If Me.txtfCode.Text.Trim <> "" Then
                    Sql &= "  and  fCode like '%" & Replace_Text(Me.txtfCode.Text.Trim) & "%'"
                End If
                If Me.cbxfStoreHouse.Text.Trim <> "" Then
                    If Not Me.cbxfStoreHouse.SelectedValue Is Nothing Then
                        Sql &= "  and fCode ='" & Me.cbxfStoreHouse.SelectedValue & "'"
                    Else
                        Sql &= "  and fCode like '%" & Replace_Text(Me.cbxfStoreHouse.Text.Trim) & "%' "
                    End If
                End If
                If Me.cbxfStorage.Text.Trim <> "" Then
                    If Not Me.cbxfStorage.SelectedValue Is Nothing Then
                        Sql &= "  and fStorageId='" & Me.cbxfStorage.SelectedValue & "'"
                    Else
                        Sql &= "  and fStorageId like '%" & Replace_Text(Me.cbxfStorage.Text.Trim) & "%' "
                    End If
                End If
                If Me.txtfLength.Text.Trim <> "" Then
                    Sql &= " and fLength = " & Val(Me.txtfLength.Text.Trim) & ""
                End If
                If Me.txtfWidth.Text.Trim <> "" Then
                    Sql &= " and  fWidth= " & Val(Me.txtfWidth.Text.Trim) & ""
                End If
                If Me.txtfHeight.Text.Trim <> "" Then
                    Sql &= " and  fHeight= " & Val(Me.txtfHeight.Text.Trim) & ""
                End If
            End If

        Catch ex As Exception
            MessageBox.Show("ReturnWhereExp:" & ex.Message & ex.StackTrace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
        Return Sql
    End Function

    ''' <summary>
    ''' 查詢
    ''' </summary>
    ''' <param name="WhereExp"></param>
    ''' <remarks></remarks>
    Private Sub ExecFind(ByVal WhereExp As String)
        Try
            Dim Sql As String = ""
            Dim Dtab As New DataTable
            Dim fStoreName As String = "(select fShortName from dbo.BSC_StoreHouse b where  b.fCode=a.fCode) "

            Sql &= "select Id,fCode," & fStoreName & " as fStoreName,fStorageId,fLength,fWidth,fHeight,fPrice,Isnull(fLength,0)*Isnull(fWidth,0) as fArea,Isnull(fLength,0)*Isnull(fWidth,0)*Isnull(fHeight,0) as fVolume,fStatus,Remark,case Isnull(fVirtual,0) when 0 then '否' when 1 then  '是'  else '' end as fVirtual,fBuJian=case isnull(fBuJian,0) when 0 then '否' when '' then '否' else '是' end ,fport from BSC_Storage  a " & WhereExp

            Dtab = App.ReturnDataTable(Sql)

            Me.DGView_Master.DataSource = Dtab
            BindDataGridViewCaption(Me.DGView_Master, Me.Re_CaptionHash())
            FullFormatDataGridView(Me.DGView_Master, False, False, False)
            Me.DGView_Master.Columns("fLength").DefaultCellStyle.Format = "0.00"
            Me.DGView_Master.Columns("fWidth").DefaultCellStyle.Format = "0.00"
            Me.DGView_Master.Columns("fHeight").DefaultCellStyle.Format = "0.00"
            Me.DGView_Master.Columns("fPrice").DefaultCellStyle.Format = "0.00"
            Me.DGView_Master.Columns("fArea").DefaultCellStyle.Format = "0.00"
            Me.DGView_Master.Columns("fVolume").DefaultCellStyle.Format = "0.00"
            If Me.fLoadBool = True Then
                Me.SetButton(ButtonType.Browse, True)
            End If
            Dim graph As Graphics = Me.CreateGraphics

            Dim SizeF1 As SizeF = graph.MeasureString(Convert.ToString(Dtab.Rows.Count), Me.DGView_Master.RowHeadersDefaultCellStyle.Font)

            Dim Width As Integer = 20 + SizeF1.Width
            If Me.DGView_Master.RowHeadersWidth <= Width Then
                Me.DGView_Master.RowHeadersWidth = Width + 10
            End If

            Me.DGView_Master.Refresh()
            Me.DGView_Master.Update()
        Catch ex As Exception
            MessageBox.Show("ExecFind:" & ex.Message & ex.StackTrace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

#End Region

#Region "初始化"

    ''' <summary>
    ''' 初始化事件
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub Initialize()
        Try
            setControlsbEnabled(New Control() {}, False)
            StoreDset = Me.ReturnInitData()
            fFillBool = False
            FillCombox()
            fFillBool = True
            Me.cbxfStoreHouse.Text = PubCompanyName
            AddHandlers(New Control() {})
        Catch ex As Exception
            MessageBox.Show("Initialize:" & ex.Message & ex.StackTrace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

    ''' <summary>
    ''' 數據集
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function ReturnInitData() As DataSet
        Dim Dset As New DataSet
        Dim sql As String = ""

        sql &= " select fCode,fShortName,fstatus from dbo.BSC_StoreHouse  where fstatus=0" & vbCrLf
        sql &= " select fCode,fStorageId from BSC_Storage " & vbCrLf
        Dset = App.ReturnDataset(sql)

        Return Dset
    End Function

    ''' <summary>
    ''' 填充下拉列表
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub FillCombox()
        ''倉庫
        Me.cbxfStoreHouse.DataSource = StoreDset.Tables(0)
        Me.cbxfStoreHouse.DisplayMember = "fShortName"
        Me.cbxfStoreHouse.ValueMember = "fCode"
        Me.cbxfStoreHouse.Update()
    End Sub

#End Region

#Region "狀態"

    ''' <summary>
    ''' 設置按鈕狀態
    ''' </summary>
    ''' <param name="type">操作類型</param>
    ''' <param name="IsFind">是否是流覽</param>
    ''' <remarks></remarks>
    Private Sub SetButton(ByVal type As ButtonType, ByVal IsFind As Boolean)
        Try

            Dim fCurrentBool As Boolean = False

            Dim I As Integer = -1
            Dim RowCount As Integer = Me.DGView_Master.Rows.Count
            If Not Me.DGView_Master.CurrentRow Is Nothing AndAlso Me.DGView_Master.CurrentRow.Cells("fCode").Value.ToString.Trim.ToLower = PubCompanyCode.ToLower Then
                fCurrentBool = True
                I = Me.DGView_Master.CurrentRow.Index
            End If
            Select Case type
                Case ButtonType.Add
                    With MainForm
                        .ToolStripAdd.Enabled = False
                        .ToolStripEdit.Enabled = False
                        .ToolStripDelete.Enabled = False
                        .ToolStripSave.Enabled = True
                        .ToolStripCancel.Enabled = True
                        .ToolStripFirst.Enabled = False
                        .ToolStripLast.Enabled = False
                        .ToolStripNext.Enabled = False
                        .ToolStripPrivous.Enabled = False
                        .ToolStripExport.Enabled = IsFind
                        .ToolStripImport.Enabled = True
                        .ToolStripPrint.Enabled = IsFind
                        .ToolStripFilter.Enabled = True

                    End With

                Case ButtonType.Browse
                    With MainForm
                        .ToolStripAdd.Enabled = True
                        .ToolStripEdit.Enabled = IsFind AndAlso fCurrentBool
                        .ToolStripDelete.Enabled = IsFind AndAlso fCurrentBool
                        .ToolStripSave.Enabled = False
                        .ToolStripCancel.Enabled = False
                        .ToolStripFirst.Enabled = IsFind AndAlso (I > 0 AndAlso RowCount > 0)
                        .ToolStripLast.Enabled = IsFind AndAlso (RowCount > 0 AndAlso I < RowCount - 1)
                        .ToolStripNext.Enabled = IsFind AndAlso (RowCount > 0 AndAlso I < RowCount - 1)
                        .ToolStripPrivous.Enabled = IsFind AndAlso (RowCount > 0 AndAlso I > 0)
                        .ToolStripExport.Enabled = IsFind
                        .ToolStripImport.Enabled = True
                        .ToolStripPrint.Enabled = IsFind
                        .ToolStripFilter.Enabled = True
                        .ToolStripCheck.Enabled = False
                        .ToolStripComplete.Enabled = False
                        .ToolStripUnCheck.Enabled = False
                    End With

                Case ButtonType.Cancel
                    With MainForm
                        .ToolStripAdd.Enabled = True
                        .ToolStripEdit.Enabled = IsFind AndAlso fCurrentBool
                        .ToolStripDelete.Enabled = IsFind AndAlso fCurrentBool
                        .ToolStripSave.Enabled = False
                        .ToolStripCancel.Enabled = False
                        .ToolStripFirst.Enabled = IsFind
                        .ToolStripLast.Enabled = IsFind
                        .ToolStripNext.Enabled = IsFind
                        .ToolStripPrivous.Enabled = IsFind
                        .ToolStripExport.Enabled = IsFind
                        .ToolStripImport.Enabled = True
                        .ToolStripPrint.Enabled = IsFind
                        .ToolStripFilter.Enabled = True

                    End With

                Case ButtonType.Edit
                    With MainForm
                        .ToolStripAdd.Enabled = False
                        .ToolStripEdit.Enabled = False
                        .ToolStripDelete.Enabled = False
                        .ToolStripSave.Enabled = True
                        .ToolStripCancel.Enabled = True
                        .ToolStripFirst.Enabled = False
                        .ToolStripLast.Enabled = False
                        .ToolStripNext.Enabled = False
                        .ToolStripPrivous.Enabled = False
                        .ToolStripExport.Enabled = IsFind
                        .ToolStripImport.Enabled = True
                        .ToolStripPrint.Enabled = IsFind
                        .ToolStripFilter.Enabled = True

                    End With

            End Select
        Catch ex As Exception
            MsgBox(ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try

    End Sub

#End Region

#Region "填充明細"

    ''' <summary>
    ''' 填充明細
    ''' </summary>
    ''' <param name="fCode"></param>
    ''' <param name="fStorageId"></param>
    ''' <remarks></remarks>
    Private Sub FillDetail(Optional ByVal fCode As String = "", Optional ByVal fStorageId As String = "")
        Try
            Dim Filter As String = "Isnull(fCode,'')='" & fCode & "'  and Isnull(fStorageId,'')='" & fStorageId & "'"
            Dim Dtab As DataTable = DirectCast(Me.DGView_Master.DataSource, DataTable)
            Dim DRow() As DataRow = Dtab.Select(Filter)
            If DRow.Length > 0 Then
                Me.txtStoreName.Text = DRow(0).Item("fStoreName") & ""
                Me.txtStorageCode.Text = DRow(0).Item("fStorageId") & ""
                Me.txtLength.Text = DRow(0).Item("fLength").ToString.Trim & ""
                Me.txtWidth.Text = DRow(0).Item("fWidth").ToString.Trim & ""
                Me.txtHeight.Text = DRow(0).Item("fHeight").ToString.Trim & ""
                Me.txtPrice.Text = DRow(0).Item("fPrice").ToString.Trim & ""
                Me.txtRemark.Text = DRow(0).Item("Remark") & ""
                Me.txtfArea.Text = Val(DRow(0).Item("fArea") & "").ToString("0.00")
                Me.txtfVolume.Text = Val(DRow(0).Item("fVolume") & "").ToString("0.00")
                Me.TxtPort.Text = DRow(0).Item("fport") & ""
                If DRow(0).Item("fVirtual").ToString.Trim = "是" Then
                    Me.CheckBox1.Checked = True
                Else
                    Me.CheckBox1.Checked = False
                End If
                If DRow(0).Item("fBuJian").ToString.Trim = "是" Then
                    Me.CheckBox2.Checked = True
                Else
                    Me.CheckBox2.Checked = False
                End If
            Else
                Me.txtStoreName.Text = ""
                Me.txtStorageCode.Text = ""
                Me.txtLength.Text = ""
                Me.txtWidth.Text = ""
                Me.txtHeight.Text = ""
                Me.txtPrice.Text = ""
                Me.txtRemark.Text = ""
                Me.txtfArea.Text = ""
                Me.txtfVolume.Text = ""
                Me.CheckBox1.Checked = False
                Me.CheckBox2.Checked = False
            End If

        Catch ex As Exception
            MessageBox.Show("FillDetail:" & ex.Message & ex.StackTrace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

#End Region

#Region "添加事件"

    ''' <summary>
    ''' KeyDown 事件
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub Text_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        Try
            Select Case e.KeyCode
                Case Keys.Enter
                    If e.Shift = True Then
                        If TypeOf sender Is ComboBox AndAlso CType(sender, ComboBox).DroppedDown = True Then
                            CType(sender, ComboBox).DroppedDown = False
                        End If
                        SendKeys.Send("+{Tab}")
                        SendKeys.Send("{F4}")
                    Else
                        If TypeOf sender Is ComboBox AndAlso CType(sender, ComboBox).DroppedDown = True Then
                            CType(sender, ComboBox).DroppedDown = False
                        End If
                        SendKeys.Send("{Tab}")
                        SendKeys.Send("{F4}")
                    End If
                Case Else

            End Select
        Catch ex As Exception
            MessageBox.Show("Text_KeyDown:" & ex.Message & ex.StackTrace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

    ''' <summary>
    ''' 添加事件
    ''' </summary>
    ''' <param name="Pans"></param>
    ''' <remarks></remarks>
    Private Sub AddHandlers(ByVal Pans() As Control)
        Try
            For Each Pan As Control In Pans
                For Each Ctrl As Control In Pan.Controls
                    If TypeOf Ctrl Is TextBox _
                       OrElse TypeOf Ctrl Is ComboBox Then
                        AddHandler Ctrl.KeyDown, AddressOf Text_KeyDown
                    End If
                Next
            Next
        Catch ex As Exception
            MessageBox.Show("AddHandlers:" & ex.Message & ex.StackTrace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

#End Region

#Region "數據處理"

    ''' <summary>
    ''' 驗證過程
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function Validated1() As Boolean
        Try
            If Me.txtStorageCode.Text.Trim = "" Then
                MessageBox.Show(My.Resources.NotNullStorageCode, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
                Me.txtStorageCode.Focus()
                Me.txtStorageCode.SelectAll()
                Return False
            End If
            If ActionHelp = IDServer.IDServer.ActionBtn.ActionAdd Then
                If Me.JudgementfStorageIdExist(Replace_Text(Me.txtStorageCode.Text.Trim)) = True Then
                    MessageBox.Show(My.Resources.ExistSameStorageCode, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
                    Me.txtStorageCode.Focus()
                    Me.txtStorageCode.SelectAll()
                    Return False
                End If
            Else

            End If

            If Val(Me.txtLength.Text.Trim) < 0 Then
                MessageBox.Show(My.Resources.notfewlengthstorage, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
                Me.txtLength.Focus()
                Me.txtLength.SelectAll()
                Return False
            End If

            If Val(Me.txtWidth.Text.Trim) < 0 Then
                MessageBox.Show(My.Resources.notfewwidthstorage, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
                Me.txtWidth.Focus()
                Me.txtWidth.SelectAll()
                Return False
            End If

            If Val(Me.txtHeight.Text.Trim) < 0 Then
                MessageBox.Show(My.Resources.notfewhightstorage, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
                Me.txtHeight.Focus()
                Me.txtHeight.SelectAll()
                Return False
            End If

            If Val(Me.txtPrice.Text.Trim) < 0 Then
                MessageBox.Show(My.Resources.notfewpricestorage, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
                Me.txtPrice.Focus()
                Me.txtPrice.SelectAll()
                Return False
            End If

            Return True
        Catch ex As Exception
            MessageBox.Show("Validated1:" & ex.Message & ex.StackTrace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Function

    ''' <summary>
    ''' 是否存在相同編號
    ''' </summary>
    ''' <param name="fStorageId">庫位編號</param>
    ''' <param name="fOldStorageId"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function JudgementfStorageIdExist(ByVal fStorageId As String, Optional ByVal fOldStorageId As String = "") As Boolean

        ''Isnull(fCode,'')='" & PubCompanyCode & "' and 
        Dim Bool As Boolean = False
        Dim Sql As String = ""
        Sql &= " select * from BSC_Storage  where Isnull(fStorageId,'')='" & fStorageId & "'"
        Dim Dtab As New DataTable
        Dtab = App.ReturnDataTable(Sql)
        If Dtab.Rows.Count > 0 Then
            Bool = True
        End If
        Return Bool
    End Function

    Private Function IsControlStoreplace(ByVal currentstore As String) As Boolean
        Dim A As Boolean = True
        Dim sql As String = "select fcode ,fstoreplace  from  BSC_StoreHouse where fstoreplace=1 and fcode='" & currentstore & "'"
        Dim rst As DataSet = New DataSet()
        rst = ReturnDataset(sql)
        If rst.Tables(0).Rows.Count > 0 Then
            A = True
        Else
            A = False
        End If
        Return A
    End Function


    Private Function btnActionSave() As Boolean
        Dim SqlCn As New SqlConnection
        Dim SqlCmd As New SqlCommand
        SqlCn = App.GetConn()
        Try
            If Me.Validated1() = False Then Return False

            Dim Sql As String = ""
            Dim fCode As String = PubCompanyCode
            Dim fStorageId As String = Replace_Text(Me.txtStorageCode.Text.Trim)
            Dim fLength As Double = Val(Me.txtLength.Text.Trim)
            Dim fWidth As Double = Val(Me.txtWidth.Text.Trim)
            Dim fHeight As Double = Val(Me.txtHeight.Text.Trim)
            Dim fPrice As Double = Val(Me.txtPrice.Text.Trim)
            Dim Remark As String = Me.txtRemark.Text.Trim & ""
            Dim fport As String = Me.TxtPort.Text.ToString.Trim

            Dim fVirtual As Int32 = 0
            Dim fBuJian As Integer = 0
            Dim fIsTemp As Integer = 0
            If Me.CheckBox1.Checked = True Then
                fVirtual = 1
            End If
            If Me.CheckBox2.Checked = True Then
                fBuJian = 1
            End If
            If Me.CheckBox3.Checked = True Then
                fIsTemp = 1
            End If

            If IsControlStoreplace(PubCompanyCode) = False Then
                MessageBox.Show(My.Resources.NotAllowAddStorepLace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
                Exit Function
            End If

            If ActionHelp = IDServer.IDServer.ActionBtn.ActionAdd Then

                Sql &= "  Insert Into BSC_Storage(fCode,fStorageId,fLength,fWidth,fHeight,fPrice,Remark,fVirtual,fBuJian,fIsTemp,fport)"
                Sql &= "  values('" & fCode & "','" & fStorageId & "'," & fLength & "," & fWidth & "," & fHeight & "," & fPrice & ",'" & Remark & "'," & fVirtual & "," & fBuJian & "," & fIsTemp & ",'" & fport & "')"

            Else

                Sql &= "  Update BSC_Storage Set fStorageId='" & fStorageId & "', fLength=" & fLength & ",fWidth=" & fWidth & " ,fHeight=" & fHeight & " ,fPrice=" & fPrice & ",Remark='" & Remark & "',fVirtual=" & fVirtual & ",fBuJian=" & fBuJian & ",fport='" & fport & "',fIsTemp=" & fIsTemp
                Sql &= "  where fCode='" & fCode & "' and fStorageId='" & fStorageId & "'"

            End If


            With SqlCmd
                .CommandType = CommandType.Text
                .CommandText = Sql
                .Connection = SqlCn
                .ExecuteNonQuery()
            End With

            MessageBox.Show(IIf(ActionHelp = IDServer.IDServer.ActionBtn.ActionAdd, My.Resources.AddSuccess, My.resources.EditSuccess), Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
            UpdateData()
            setControlsbEnabled(New Control() {}, False)
            ActionHelp = IDServer.IDServer.ActionBtn.ActionHelp
            Me.SetButton(ButtonType.Browse, True)
            Return True
        Catch ex As Exception
            MessageBox.Show("btnActionSave:" & ex.Message & ex.StackTrace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Function


    ''' <summary>
    ''' 更新數據
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function UpdateData()
        Try
            Dim Dtab As DataTable = DirectCast(Me.DGView_Master.DataSource, DataTable)

            If ActionHelp = IDServer.IDServer.ActionBtn.ActionAdd Then
                Dim Row As DataRow = Dtab.NewRow

                Row("fCode") = PubCompanyCode
                Row("fStoreName") = PubCompanyName
                Row("fStorageId") = Me.txtStorageCode.Text.Trim
                Row("fLength") = Val(Me.txtLength.Text.Trim)
                Row("fWidth") = Val(Me.txtWidth.Text.Trim)
                Row("fHeight") = Val(Me.txtHeight.Text.Trim)
                Row("fPrice") = Val(Me.txtPrice.Text.Trim)
                Row("Remark") = Me.txtRemark.Text.Trim
                If Me.CheckBox1.Checked = True Then
                    Row("fVirtual") = "是"
                Else
                    Row("fVirtual") = "否"
                End If
                Dtab.Rows.Add(Row)
            Else
                Dim DRow() As DataRow = Dtab.Select("Isnull(fCode,'')='" & PubCompanyCode & "' and Isnull(fStorageId,'')='" & Me.txtStorageCode.Text.Trim & "'")
                If DRow.Length > 0 Then
                    DRow(0).Item("fLength") = Val(Me.txtLength.Text.Trim)
                    DRow(0).Item("fWidth") = Val(Me.txtWidth.Text.Trim)
                    DRow(0).Item("fHeight") = Val(Me.txtHeight.Text.Trim)
                    DRow(0).Item("fPrice") = Val(Me.txtPrice.Text.Trim)
                    DRow(0).Item("Remark") = Me.txtRemark.Text.Trim
                    If Me.CheckBox1.Checked = True Then
                        DRow(0)("fVirtual") = "是"
                    Else
                        DRow(0)("fVirtual") = "否"
                    End If
                End If
            End If

            Me.txtfArea.Text = Val(Val(Me.txtLength.Text.Trim & "") * Val(Me.txtWidth.Text.Trim & "")).ToString("0.00")
            Me.txtfArea.Text = Val(Val(Me.txtLength.Text.Trim & "") * Val(Me.txtWidth.Text.Trim & "") * Val(Me.txtHeight.Text.Trim & "")).ToString("0.00")

            Dtab.AcceptChanges()

            Me.DGView_Master.Update()
        Catch ex As Exception
            MessageBox.Show("UpdateData:" & ex.Message & ex.StackTrace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Function

#End Region

#End Region

#Region "Controls Events"

#Region "位置控制"

    Private Sub Panel4_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel4.Resize
        Try
        Catch ex As Exception
            MessageBox.Show("Panel4_Resize:" & ex.Message & ex.StackTrace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

#End Region

#Region "窗體加載"

    Private Sub Frm_BSCBin_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            Me.fLoadBool = False
            Initialize()
            Dim WhereExp As String = Me.ReturnWhereExp()
            Me.ExecFind(WhereExp)
            Me.btnFind.Enabled = FindEnable
            Me.fLoadBool = True
        Catch ex As Exception
            MessageBox.Show("Frm_BSCBin_Load:" & ex.Message & ex.StackTrace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

#End Region

#Region "值改變事件"

    Private Sub cbxfStoreHouse_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbxfStoreHouse.SelectedValueChanged
        Try
            If Me.fFillBool = False Then Exit Sub
            Dim fCode As String = ""
            If Not Me.cbxfStoreHouse.SelectedValue Is Nothing Then
                fCode = Me.cbxfStoreHouse.SelectedValue
            End If

            Dim Dtab As DataTable = StoreDset.Tables(1).Copy
            Dtab.DefaultView.RowFilter = "fCode='" & fCode & "'"
            Me.cbxfStorage.DataSource = Dtab
            Me.cbxfStorage.DisplayMember = "fStorageId"
            Me.cbxfStorage.ValueMember = "fStorageId"
            Me.cbxfStorage.Text = ""

        Catch ex As Exception
            MessageBox.Show("cbxfStoreHouse_SelectedValueChanged:" & ex.Message & ex.StackTrace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

#End Region

#Region "Button 事件"

    Private Sub btnFind_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFind.Click
        Try
            MainForm.ToolStripFind_Click(Nothing, Nothing)
        Catch ex As Exception
            MessageBox.Show("btnFind_Click:" & ex.Message & ex.StackTrace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

    Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
        MainForm.ToolStripSave_Click(Nothing, Nothing)
    End Sub

    Private Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        MainForm.ToolStripCancel_Click(Nothing, Nothing)
    End Sub

#End Region

#Region "TabControl"

    Private Sub TabControl1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TabControl1.KeyDown
        Try
            If ActionHelp = IDServer.IDServer.ActionBtn.ActionAdd OrElse ActionHelp = IDServer.IDServer.ActionBtn.ActionEdit Then
                If e.Control = True Then
                    Select Case e.KeyCode

                        Case Keys.S
                            MainForm.ToolStripSave_Click(Nothing, Nothing)
                        Case Keys.Z
                            MainForm.ToolStripCancel_Click(Nothing, Nothing)
                        Case Else

                    End Select
                End If
            End If
        Catch ex As Exception
            MessageBox.Show("TabControl1_KeyDown:" & ex.Message & ex.StackTrace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

    ''' <summary>
    ''' 填充明細
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
        Try
            If Me.TabControl1.SelectedIndex = 1 Then
                Dim fCode As String = ""
                Dim fStorageId As String = ""
                If Not Me.DGView_Master.CurrentRow Is Nothing Then
                    fCode = Me.DGView_Master.CurrentRow.Cells("fCode").Value & ""
                    fStorageId = Me.DGView_Master.CurrentRow.Cells("fStorageId").Value & ""
                End If
                Me.FillDetail(fCode, fStorageId)
            End If
        Catch ex As Exception
            MessageBox.Show("TabControl1_SelectedIndexChanged:" & ex.Message & ex.Message, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

    Private Sub TabControl1_Selecting(ByVal sender As Object, ByVal e As System.Windows.Forms.TabControlCancelEventArgs) Handles TabControl1.Selecting
        If ActionHelp = IDServer.IDServer.ActionBtn.ActionAdd OrElse ActionHelp = IDServer.IDServer.ActionBtn.ActionEdit Then
            e.Cancel = True
        End If
    End Sub

#End Region

#Region "網格事件"

    ''' <summary>
    ''' 轉到明細
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub DGView_Master_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGView_Master.CellDoubleClick
        Try
            Me.TabControl1.SelectedIndex = 1
        Catch ex As Exception
            MessageBox.Show("DGView_Master_CellDoubleClick:" & ex.Message & ex.StackTrace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

    ''' <summary>
    ''' 繪制行號
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub DGView_Master_RowPostPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles DGView_Master.RowPostPaint
        Try
            Dim Grid As DataGridView = DirectCast(sender, DataGridView)
            Dim SBrush As New SolidBrush(Grid.RowHeadersDefaultCellStyle.ForeColor)
            e.Graphics.DrawString(Convert.ToString(e.RowIndex + 1, System.Globalization.CultureInfo.CurrentCulture), e.InheritedRowStyle.Font, SBrush, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4)
        Catch ex As Exception
            MessageBox.Show("DGView_Master_RowPostPaint:" & ex.Message & ex.StackTrace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

#End Region

#Region "KeyPress 事件"


    Private Sub txtLength_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtLength.KeyPress, txtWidth.KeyPress, txtHeight.KeyPress, txtPrice.KeyPress
        Try
            If Char.IsControl(e.KeyChar) = True Then
                Exit Sub
            End If
            Dim TextBox1 As TextBox = DirectCast(sender, TextBox)
            Dim TextValue As String = ""
            If TextBox1.SelectionLength > 0 Then
                TextValue = TextBox1.Text.Substring(0, TextBox1.SelectionStart) & e.KeyChar & TextBox1.Text.Substring(TextBox1.SelectionStart + TextBox1.SelectionLength)
            Else
                TextValue = TextBox1.Text.Substring(0, TextBox1.SelectionStart) & e.KeyChar & TextBox1.Text.Substring(TextBox1.SelectionStart)
            End If
            If TextValue.Trim <> "" Then
                If ValidatedIsNumeric(TextValue, 2, 2) = False Then
                    e.Handled = True
                End If
            End If
        Catch ex As Exception
            MessageBox.Show("txtLength_KeyPress:" & ex.Message & ex.StackTrace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

#End Region

#Region "值改變事件"

    Private Sub txtfLength_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtLength.TextChanged, txtWidth.TextChanged, txtHeight.TextChanged
        Try
            If ActionHelp = IDServer.IDServer.ActionBtn.ActionAdd OrElse ActionHelp = IDServer.IDServer.ActionBtn.ActionEdit Then
                Dim TextBoxEx As TextBox = DirectCast(sender, TextBox)
                Select Case TextBoxEx.Name.ToLower
                    Case Me.txtLength.Name.ToLower, Me.txtWidth.Name.ToLower
                        Me.txtfArea.Text = Val(Val(Me.txtLength.Text.Trim & "") * Val(Me.txtWidth.Text.Trim & "")).ToString("0.00")
                        Me.txtfVolume.Text = Val(Val(Me.txtLength.Text.Trim & "") * Val(Me.txtWidth.Text.Trim & "") * Val(Me.txtHeight.Text.Trim & "")).ToString("0.00")
                    Case Me.txtHeight.Name.ToLower
                        Me.txtfVolume.Text = Val(Val(Me.txtLength.Text.Trim & "") * Val(Me.txtWidth.Text.Trim & "") * Val(Me.txtHeight.Text.Trim & "")).ToString("0.00")
                End Select
            End If
        Catch ex As Exception
            MessageBox.Show("txtfLength_TextChanged:" & ex.Message & ex.StackTrace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

#End Region

    Private Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        If Me.CheckBox1.Checked = True Then
            Me.CheckBox2.Checked = False
            Me.CheckBox3.Checked = False
        End If
    End Sub

    Private Sub CheckBox2_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
        If Me.CheckBox2.Checked = True Then
            Me.CheckBox1.Checked = False
            Me.CheckBox3.Checked = False
        End If
    End Sub

    Private Sub CheckBox3_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox3.CheckedChanged
        If Me.CheckBox3.Checked = True Then
            Me.CheckBox1.Checked = False
            Me.CheckBox2.Checked = False
        End If
    End Sub
#End Region

#Region "Interface Define"


    ''' <summary>
    ''' 新增
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function ActionAdd() As Boolean Implements IDServer.IDServer.IDServer.ActionAdd
        Try
            If AddEnable = False Then
                MessageBox.Show(My.Resources.NotAllowAdd, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
                Exit Function
            End If

            If Me.TabControl1.SelectedIndex = 0 Then
                Me.TabControl1.SelectedIndex = 1
            End If
            ActionHelp = IDServer.IDServer.ActionBtn.ActionAdd
            Me.FillDetail()
            Me.SetButton(ButtonType.Add, False)
            setControlsbEnabled(New Control() {}, True)
            Me.txtStoreName.Text = PubCompanyName
            Me.txtStoreName.ReadOnly = True
            Me.txtfArea.ReadOnly = True
            Me.txtfVolume.ReadOnly = True

            Me.txtStorageCode.Focus()
            Return True
        Catch ex As Exception
            ''MessageBox.Show("ActionAdd:" & ex.Message & ex.StackTrace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Function

    Public Function ActionCancel() As Boolean Implements IDServer.IDServer.IDServer.ActionCancel
        Try
            ActionHelp = IDServer.IDServer.ActionBtn.ActionHelp
            Dim fCode As String = ""
            Dim fStorageId As String = ""
            Dim Bool As Boolean = False
            If Not Me.DGView_Master.CurrentRow Is Nothing Then
                fCode = Me.DGView_Master.CurrentRow.Cells("fCode").Value & ""
                fStorageId = Me.DGView_Master.CurrentRow.Cells("fStorageId").Value & ""
                Bool = True
            End If
            Me.FillDetail(fCode, fStorageId)
            setControlsbEnabled(New Control() {}, False)
            Me.SetButton(ButtonType.Browse, Bool)
            Return True
        Catch ex As Exception
            MessageBox.Show(":ActionCancel" & ex.Message & ex.StackTrace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Function

    ''' <summary>
    ''' 刪除
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function ActionDelete() As Boolean Implements IDServer.IDServer.IDServer.ActionDelete

        Dim SqlCn As SqlConnection = App.GetConn()
        Dim SqlCmd As New SqlCommand
        Try
            If DeleteEnable = False Then
                MessageBox.Show(My.resources.NotAllowDelete, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
                Exit Function
            End If


            If Me.DGView_Master.CurrentRow Is Nothing Then Return False

            If MessageBox.Show(My.Resources.ConfirmDelete, Msg.CompanyName, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) <> DialogResult.OK Then Return False

            Dim fCode As String = Me.DGView_Master.CurrentRow.Cells("fCode").Value & ""
            Dim fStorageId As String = Me.DGView_Master.CurrentRow.Cells("fStorageId").Value & ""

            Dim Sql As String = "  Delete BSC_Storage where Isnull(fCode,'')='" & fCode & "' and Isnull(fStorageId,'')='" & fStorageId & "'"

            With SqlCmd
                .CommandText = Sql
                .CommandType = CommandType.Text
                .Connection = SqlCn
                .ExecuteNonQuery()
            End With

            Dim Dtab As DataTable = DirectCast(Me.DGView_Master.DataSource, DataTable)

            Dim DRow() As DataRow = Dtab.Select("Isnull(fCode,'')='" & fCode & "'  and Isnull(fStorageId,'')='" & fStorageId & "'")
            If DRow.Length > 0 Then
                DRow(0).Delete()
            End If
            Dtab.AcceptChanges()

            MessageBox.Show(My.Resources.DeleteSuccess, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)


            If Me.TabControl1.SelectedIndex = 1 AndAlso Not Me.DGView_Master.CurrentRow Is Nothing Then
                Dim fCodeKey As String = Me.DGView_Master.CurrentRow.Cells("fCode").Value & ""
                Dim fStorageIdKey As String = Me.DGView_Master.CurrentRow.Cells("fStorageId").Value & ""
                Me.FillDetail(fCodeKey, fStorageIdKey)
            End If

        Catch ex As Exception
            MessageBox.Show("ActionDelete:" & ex.Message & ex.StackTrace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Function

    Public Function ActionEdit() As Boolean Implements IDServer.IDServer.IDServer.ActionEdit
        Try
            If EditEnable = False Then
                MessageBox.Show(My.resources.NotAllowEidt, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
                Exit Function
            End If

            If Me.DGView_Master.CurrentRow Is Nothing Then Exit Function
            If Me.DGView_Master.CurrentRow.Cells("fCode").Value.ToString.Trim.ToLower <> PubCompanyCode.ToLower Then
                MessageBox.Show(My.Resources.Eidtcurrentstorage, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
                Return False
            End If
            If Me.TabControl1.SelectedIndex = 0 Then
                Me.TabControl1.SelectedIndex = 1
            End If
            ActionHelp = IDServer.IDServer.ActionBtn.ActionEdit
            Me.SetButton(ButtonType.Add, False)
            setControlsbEnabled(New Control() {}, True)
            Me.txtStoreName.Text = PubCompanyName
            Me.txtStoreName.ReadOnly = True
            Me.txtStorageCode.ReadOnly = True
            Me.txtfArea.ReadOnly = True
            Me.txtfVolume.ReadOnly = True

            Me.txtLength.Focus()
            Return True
        Catch ex As Exception
            MessageBox.Show("ActionEdit:" & ex.Message & ex.StackTrace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Function

    Public Function ActionExport() As Boolean Implements IDServer.IDServer.IDServer.ActionExport
        Try
            Dim mBill As System.Text.StringBuilder = New System.Text.StringBuilder
            Dim SQL As String = String.Empty
            Dim DS As DataSet
            Dim mTable As DataTable = New DataTable
            Dim CTable As DataTable = New DataTable
            Dim CasioNum As String = String.Empty

            Dim Xmlpath As String = ReturnXMLPathDown()
            If Xmlpath.Length = 0 Then
                MessageBox.Show("沒有設置下載路徑", "路徑設置", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                Exit Function
            End If

            SQL = "select fStorageId as BinNo from BSC_Storage where fCode ='" & Me.cbxfStoreHouse.SelectedValue & "';"
            SQL &= "select distinct ListA from dbo.BSC_OtherDefineB where  ItemNo = '95' and ListB = '" & Me.cbxfStoreHouse.SelectedValue & "' "
            DS = App.ReturnDataset(SQL)
            mTable = DS.Tables(0)
            CTable = DS.Tables(1)
            If CTable.Rows.Count <= 0 Then
                MessageBox.Show("" & Me.cbxfStoreHouse.Text & " 沒有設置Casio編號", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Information)
                Exit Function
            End If
            For Each row As DataRow In CTable.Rows
                Dim CNO As String = String.Empty
                CNO = row(0)
                Dim Xml As String = Xmlpath + "Bin-" + CNO + ".XML"
                mTable.WriteXml(Xml, System.Data.XmlWriteMode.WriteSchema, True)
            Next
            MessageBox.Show("保存成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show("Error:BtnCasioXml_Click" + ex.ToString)
        End Try
    End Function

    Public Function ActionFilter() As Boolean Implements IDServer.IDServer.IDServer.ActionFilter

    End Function

    Public Function ActionGoFirst() As Boolean Implements IDServer.IDServer.IDServer.ActionGoFirst
        Try
            If Me.DGView_Master.Rows.Count > 0 Then
                Me.DGView_Master.CurrentCell = Me.DGView_Master.Rows(0).Cells(1)
                Me.SetButton(ButtonType.Browse, True)
                If Me.TabControl1.SelectedIndex = 1 Then
                    Dim fCode As String = ""
                    Dim fStorageId As String = ""
                    If Not Me.DGView_Master.CurrentRow Is Nothing Then
                        fCode = Me.DGView_Master.CurrentRow.Cells("fCode").Value & ""
                        fStorageId = Me.DGView_Master.CurrentRow.Cells("fStorageId").Value & ""
                    End If
                    Me.FillDetail(fCode, fStorageId)
                End If
            End If
        Catch ex As Exception
            MessageBox.Show("ActionGoFirst:" & ex.Message & ex.StackTrace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Function

    Public Function ActionGoLast() As Boolean Implements IDServer.IDServer.IDServer.ActionGoLast
        If Me.DGView_Master.Rows.Count > 0 Then
            Me.DGView_Master.CurrentCell = Me.DGView_Master.Rows(Me.DGView_Master.Rows.Count - 1).Cells(1)
            Me.SetButton(ButtonType.Browse, True)
            If Me.TabControl1.SelectedIndex = 1 Then
                Dim fCode As String = ""
                Dim fStorageId As String = ""
                If Not Me.DGView_Master.CurrentRow Is Nothing Then
                    fCode = Me.DGView_Master.CurrentRow.Cells("fCode").Value & ""
                    fStorageId = Me.DGView_Master.CurrentRow.Cells("fStorageId").Value & ""
                End If
                Me.FillDetail(fCode, fStorageId)
            End If
        End If
    End Function

    Public Function ActionGoNext() As Boolean Implements IDServer.IDServer.IDServer.ActionGoNext
        If Me.DGView_Master.Rows.Count > 0 AndAlso Not Me.DGView_Master.CurrentRow Is Nothing Then
            Dim I As Int32 = Me.DGView_Master.CurrentRow.Index + 1
            If I < Me.DGView_Master.Rows.Count Then
                Me.DGView_Master.CurrentCell = Me.DGView_Master.Rows(I).Cells(1)
                Me.SetButton(ButtonType.Browse, True)
                If Me.TabControl1.SelectedIndex = 1 Then
                    Dim fCode As String = ""
                    Dim fStorageId As String = ""
                    If Not Me.DGView_Master.CurrentRow Is Nothing Then
                        fCode = Me.DGView_Master.CurrentRow.Cells("fCode").Value & ""
                        fStorageId = Me.DGView_Master.CurrentRow.Cells("fStorageId").Value & ""
                    End If
                    Me.FillDetail(fCode, fStorageId)
                End If
            End If
        End If
    End Function

    Public Function ActionGoPrevious() As Boolean Implements IDServer.IDServer.IDServer.ActionGoPrevious
        If Me.DGView_Master.Rows.Count > 0 AndAlso Not Me.DGView_Master.CurrentRow Is Nothing Then
            Dim I As Integer = Me.DGView_Master.CurrentRow.Index - 1
            If I >= 0 Then
                Me.DGView_Master.CurrentCell = Me.DGView_Master.Rows(I).Cells(1)
                Me.SetButton(ButtonType.Browse, True)
                If Me.TabControl1.SelectedIndex = 1 Then
                    Dim fCode As String = ""
                    Dim fStorageId As String = ""
                    If Not Me.DGView_Master.CurrentRow Is Nothing Then
                        fCode = Me.DGView_Master.CurrentRow.Cells("fCode").Value & ""
                        fStorageId = Me.DGView_Master.CurrentRow.Cells("fStorageId").Value & ""
                    End If
                    Me.FillDetail(fCode, fStorageId)
                End If
            End If
        End If
    End Function

    Public Function ActionImport() As Boolean Implements IDServer.IDServer.IDServer.ActionImport

    End Function

    Public Function ActionInitialize() As Boolean Implements IDServer.IDServer.IDServer.ActionInitialize

    End Function

    Public Function ActionPrint() As Boolean Implements IDServer.IDServer.IDServer.ActionPrint

    End Function

    Public Function ActionSave() As Boolean Implements IDServer.IDServer.IDServer.ActionSave
        Dim bool As Boolean = False
        bool = btnActionSave()
        Return bool
    End Function

    ''' <summary>
    ''' 查詢過程
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function ActionSelect() As Boolean Implements IDServer.IDServer.IDServer.ActionSelect
        Try
            Dim WhereExp As String = Me.ReturnWhereExp()
            Me.ExecFind(WhereExp)
            Return True
        Catch ex As Exception
            MessageBox.Show("ActionSelect:" & ex.Message & ex.StackTrace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Function

    ''' <summary>
    ''' 審核過成
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function ActionChecked() As Boolean
        Try
            If CheckEnable = False Then
                MessageBox.Show("對不起，您沒有審核權限", Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
                Exit Function
            End If

            Return True
        Catch ex As Exception
            MessageBox.Show("ActionChecked:" & ex.Message & ex.StackTrace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Function

    ''' <summary>
    ''' 反審核
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function ActionUnchecked() As Boolean
        Try
            If CheckEnable = False Then
                MessageBox.Show("對不起，您沒有反審核權限", Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
                Exit Function
            End If

            Return True
        Catch ex As Exception
            MessageBox.Show("ActionUnchecked:" & ex.Message & ex.StackTrace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Function

    ''' <summary>
    ''' 完成
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function ActionComplete() As Boolean
        Try
            Return True
        Catch ex As Exception
            MessageBox.Show("ActionComplete:" & ex.Message & ex.StackTrace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Function

#End Region



    Private Sub GroupBox2_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub
End Class
